package main

import (
	"fmt"
	"gitee.com/snxamdf/wui/logs"
	"os"
)

func writeDemo() {
	write("main.go", []byte(demoMain))
}

func write(path string, content []byte) {
	err := os.WriteFile(path, content, 0777)
	logs.Info("输出文件成功：", path, err)
	fmt.Println()
}

var (
	demoMain = `package main

import (
	"embed"
	"gitee.com/snxamdf/wui"
	"gitee.com/snxamdf/wui/config"
	"gitee.com/snxamdf/wui/logs"
	"gitee.com/snxamdf/wui/webview/v1.1"
	"net/url"
)

//go:embed resources
var resources embed.FS

func init() {
	logs.Info("开始 设置 go:embed", resources)
	config.SetEmbed(resources)
	logs.Info("结束 设置 go:embed", resources)
}

func main() {
	logs.Info("=============WUI 示例=============")
	wui.Init()
	const myHTML = "<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <title>Document</title> </head> <body> <div id=\"app\"> <h1>WUI 示例</h1></div> </body></html>"
	w := webview.New(webview.Settings{
		Title: "WUI Demo",
		URL: "data:text/html," + url.PathEscape(myHTML),
	})
	defer w.Exit()
	w.Run()
}
`
)
